package com.lanou.zy.projecta.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
import com.lanou.zy.projecta.R;
import com.lanou.zy.projecta.volley.VolleySingleton;


/**
 * Created by dllo on 15/10/30.
 */
public class CountryAllFragment extends Fragment {
    private static final String ARGS_URL = "photo";
    private ImageView countryViewPagerIv;
    private RequestQueue queue;
    private ImageLoader imageLoader;
    private String imgUrl;

    public CountryAllFragment() {
        super();
    }

    public static CountryAllFragment getInstance(String photo) {
        CountryAllFragment countryAllFragment = new CountryAllFragment();
        Bundle args = new Bundle();
        args.putString(ARGS_URL,photo);
        countryAllFragment.setArguments(args);
        return countryAllFragment;
    }


    @Override
    public void onAttach(Context c) {
        super.onAttach(c);
        queue = Volley.newRequestQueue(c);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_countryall, null);
        countryViewPagerIv = (ImageView) v.findViewById(R.id.countryViewPagerIv);
        return v;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        imageLoader = VolleySingleton.getInstance().getImageLoader();
        imgUrl = getArguments().getString(ARGS_URL);

        getBitmapCache(imgUrl, countryViewPagerIv);

    }

    private void getBitmapCache(String url, ImageView imageView) {
        ImageLoader.ImageListener listener = ImageLoader.getImageListener(
                imageView, R.mipmap.ic_qyer_gray_150, R.mipmap.ic_qyer_gray_150
        );
        imageLoader.get(url, listener);
    }
}
